﻿@{
    //string topicTitle = "专题商品";
    var topic = ViewBag.topic as token_shop_subject_dto;
    ViewBag.Title = topic.title;
    Layout = "~/Views/Shared/_MallLayout.cshtml";
    string img_url = ViewBag.img_url;
    merchant_dto merchant = ViewBag.merchant as merchant_dto;
    red_user_dto redcord = ViewBag.redcord as red_user_dto;
    long subject_id = ViewBag.subject_id;
    long shop_id = 0;
    string shopId = Request["shopId"] == null ? "0" : Request["shopId"].ToString();
    long.TryParse(shopId, out shop_id);
}
@section style{
    <link href="~/Scripts/mescroll/mescroll.min.css" rel="stylesheet" />
    <style type="text/css">
        .mescroll {
            position: absolute;
            top: 2.0rem;
            bottom: 0;
            height: auto;
        }
    </style>
}
    <body class="page-index page-distributionStore">
        <div class="mod-type mod-typeTab">
            <ul id="status">
                <li class="cur" value="0">全部<i></i></li>
                <li value="1">销量<i></i></li>
                <li value="2">最新<i></i></li>
            </ul>
        </div>
        <div class="mescroll" id="mescroll">
            <div class="mod-fallsceshi">
                <div class="masonry" id="dataList">
                </div>
            </div>
        </div>
        <a class="goTop">
            <img src="~/Content/css/tokenmall/img/icon/goTop.png" />
        </a>
        <div class="mod-popFx popFx trans_5 j-sharePro">
            <i class="icon-close2 j-close"></i>
            <div class="popView">
                <div class="top">
                    <img src="" alt="" id="popimg">
                </div>
            </div>
            <div class="tbnBox">
                <a class="btn j-copy" data-clipboard-action="copy" data-clipboard-target="#foo" href="javascript:;">复制商品链接</a>
                <a class="btn" href="#" id="saveimg" download="">保存图片</a>
                <input type="text" class="share_code fn-hide" readonly="readonly" id="foo" value="" />
            </div>
        </div>
    </body>
@section scripts{
    <script src="~/Scripts/tokenmall/masonry-docs.min.js"></script>
    <script src="~/Scripts/tokenmall/imagesloaded.min.js"></script>
    <script src="~/Scripts/mescroll/mescroll.min.js"></script>
    <script src="~/Scripts/clipboard.min.js"></script>
    <script>
        $(function () {
            var $container = $('.masonry');
            var total_pages = 1;
            var isload = false;
            var dataUrl = '/Topic/_TopicProduct';
            var subject_id = @subject_id;
            var conditions = 0
            var mescroll = new MeScroll("mescroll", {
                down: {
                    auto: false,
                    callback: function (mescroll) {
                        $container.html('');
                        $container.masonry('layout');
                        mescroll.resetUpScroll();
                    }
                },
                up: {
                    callback: askData,
                    page: { num: 0, size: 6 },
                    clearEmptyId: "dataList",
                    isBounce: false,
                    noMoreSize: 3,
                    htmlNodata: '<p class="upwarp-nodata">亲,我是有底线的~</p >',
                    empty: { warpId: "dataList", icon: "", tip: "亲,暂时没有数据哦~" },
                    toTop: {}
                }
            });
            //异步请求数据
            function askData(pager) {
                if (!isload && total_pages >= pager.num) {
                    isload = true;
                    $.ajax({
                        type: "post",
                        url: dataUrl,
                        params: "contentType",
                        data: { page: pager.num, size: pager.size, subject_id: subject_id, conditions: conditions, shop_id: '@shop_id' },
                        async: true,
                        success: function (res) {
                            var $elems = $(res);
                            var paged = $elems.siblings("page");
                            var rows = Number.parseInt(paged.attr("rows"));
                            var total = Number.parseInt(paged.attr("total_result"));
                            mescroll.endBySize(rows, total);
                            if (paged.length == 1) {
                                total_pages = Number.parseInt(paged.attr("total_pages"));
                                msnryobj.masonryImagesReveal($elems);
                                $('#dataList page').remove();
                            } else {
                                $(".upwarp-nodata").html('亲,暂时没有数据哦~');
                            }
                            isload = false;
                        },
                        error: function (err) {
                            isload = false;
                            mescroll.endErr();
                        }
                    });
                }
            }
            var width = $container.width() / 2;
            var msnryobj = $container.masonry({ itemSelector: '.item', gutter: 0, columnWidth: width, isAnimated: true });
            $.fn.masonryImagesReveal = function ($items) {
                var msnry = this.data('masonry');
                var itemSelector = msnry.options.itemSelector;
                $items.hide();
                this.append($items);
                $items.imagesLoaded().progress(function (imgLoad, image) {
                    var $item = $(image.img).parents(itemSelector);
                    $item.show();
                    msnry.appended($item);
                });
                return this;
            };
            $("ul#status").on("click", "li", function () {
                //只需要找到你点击的是哪个ul里面的就行
                $(this).addClass("cur").siblings().removeClass("cur");
                conditions = $(this).val();
                sort = $(this).val();
                $container.html('');
                $container.masonry('layout');
                //重置列表数据
                mescroll.resetUpScroll();
                //隐藏回到顶部按钮
                mescroll.hideTopBtn();
            });

            var browser = {
                versions: function () {
                    var u = navigator.userAgent, app = navigator.appVersion;
                    return {
                        //移动终端浏览器版本信息
                        trident: u.indexOf('Trident') > -1, //IE内核
                        presto: u.indexOf('Presto') > -1, //opera内核
                        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                        iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                        iPad: u.indexOf('iPad') > -1, //是否iPad
                        webApp: u.indexOf('Safari') == -1, //是否web应该程序，没有头部与底部,
                        WeiXin: u.match(/MicroMessenger/i) == "MicroMessenger" //是否为微信客户端
                    };
                }(),
                language: (navigator.browserLanguage || navigator.language).toLowerCase()
            };
            $("#dataList .item").delegate("a", "click", function (e) {
                e.stopPropagation();
            });
            $("#dataList").delegate(".fxPro", "click", function (e) {
                e.preventDefault();
                if (@merchant.id<= 0) {
                    var loginResult = isLogin();
                    if (!loginResult)
                        return loginResult;
                    location.href = "/home/login?returnUrl=@Request.Url"; return;
                }
                var that = $(this);
                var obj = {};
                obj.name =@merchant.id> 0 ? '@merchant.name' : '';
                @{   string head_img = (string.IsNullOrEmpty(merchant.photo) ? "http://" + Request.Url.Authority + "/Content/images/my/icon.png" : string.Format("{0}{1}", img_url, merchant.photo));}
                obj.head_img_url = @merchant.id> 0 ? '@head_img' : '';
                obj.main_image_url = that.attr('data-main_image_url');
                obj.title = that.attr('data-name');
                obj.cost_price = that.attr('data-cost-price');
                obj.price = that.attr('data-price');
                obj.red_drill = that.attr("data-red-drill");
                obj.invitation_code = '@redcord.invitation_code';
                var url = 'http://' + '@Request.Url.Authority' + '/DistributionMall/ProductDetail?productId=' + that.attr('data-id');
                obj.share_url = @merchant.id> 0 ? url + '&merchant_no=' + '@merchant.merchant_no' : url;
                try {
                    var data = JSON.stringify(obj);
                    if (browser.versions.ios) {
                        if (isIOSAppNewBrowser != undefined && isIOSAppNewBrowser == true) {
                            window.webkit.messageHandlers.commodityShare.postMessage(data);
                        } else {
                            commodityShare(data)
                        }
                    } else if (browser.versions.android) {
                        androidfuntion.commodityShare(data)
                    }
                } catch (e) {
                    $('.black').addClass('cur');
                    $('.popFx').animate({ bottom: "0" });
                    var img_url = '/DistributionMall/ImageMerge?product_id=' + that.attr('data-id');
                    img_url =@merchant.id> 0 ? img_url + '&merchant_no=' + '@merchant.merchant_no' : img_url;
                    $("#popimg").attr('src', img_url);
                    $('.share_code').val(obj.share_url);
                    $("#saveimg").attr('href', img_url);
                    $("#saveimg").attr('download', obj.name + '.jpg');
                }
            });
            $('.j-copy').click(function () {
                //var ccc = $('.share_code').select(); // 选择对象
                //document.execCommand("Copy"); // 执行浏览器复制命令
                //layer.msg("复制成功");
                var clipboard = new ClipboardJS('.j-copy');

                clipboard.on('success', function (e) {
                    layer.msg("复制成功");
                });

                clipboard.on('error', function (e) {
                    console.log(e);
                });
            });

            $('.icon-close2,.black').click(function () {
                $('.popFx').animate({ bottom: "-100%" });
                $('.black').removeClass('cur');
            })





            @*//防止页面后退
            history.pushState(null, null, document.URL);
            window.onpopstate = function (e) {
                if (browser.versions.mobile) {
                    //判断是否是移动设备打开。browser代码在下面
                    var ua = navigator.userAgent.toLowerCase();
                    //获取判断用的对象
                    if (ua.match(/MicroMessenger/i) == "micromessenger") { //微信app
                        history.pushState(null, null, document.URL);
                        this.window.location.replace('@Url.Action("Index", "Consumption")');
                    } else {//非微信打开
                        if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                            try {
                                        if (isIOSAppNewBrowser != undefined && isIOSAppNewBrowser == true) {
                                            window.webkit.messageHandlers.gohome.postMessage('');
                                        } else {
                                            gohome();
                                        }
                                  }
                            catch (ex) {}
                        }
                        else if (/(Android)/i.test(navigator.userAgent)) {
                                try { androidfuntion.gohome(); }
                                catch (ex) {}
                        }
                    }
                } else {
                    //否则就是PC浏览器打开
                      history.pushState(null, null, document.URL);
                      this.window.location.replace('@Url.Action("Index", "Consumption")');
                }
            }*@

            //用click事件
            $(document).click(function (e) {
                e.stopPropagation();
            })
            $('.contactUs').click(function () {
                $('.kefu').show();
            })
            $('.kefu').click(function () {
                $('.kefu').hide();
            })
            $('.kefu .innerBox').click(function (e) {
                e.stopPropagation();
            })




        });
    </script>

}